package com.suxin.spring.config;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.concurrent.*;

/**
 * @author Tang
 * @classname DefaultThreadPoolTaskScheduler
 * @description [  ]
 * @date 2021/8/1 17:27
 */
public class DefaultThreadPoolTaskScheduler extends ThreadPoolTaskScheduler {

    public DefaultThreadPoolTaskScheduler(int poolSize, String threadNamePrefix) {
        // 核心数
        this.setPoolSize(poolSize);
        // 任务已经取消了，是否将其从任务队列中真正的移除,而不是标记删除
        this.setRemoveOnCancelPolicy(true);
        // 前缀
        this.setThreadNamePrefix(threadNamePrefix);
        // init()
        init(Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
    }

    public void init(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
        initializeExecutor(threadFactory, rejectedExecutionHandler);
    }

}